<?php require_once 'header.php'; ?>
<script>
$("title").html("注册");
</script>

<?php 

if ((!empty($_POST['email']))&&(!empty($_POST['password']))&&(!empty($_POST['yanzheng']))){
    require_once 'connect.php';
   $class=$_POST['class'];
   $shenfen=$_POST['yanzheng'];
    $className="";
    switch ($class) {
      case 1:
      $className="administrations";
        break;
      case 2:
      if ($shenfen!="teacher") {
        echo "<script>alert('身份码错误，请输入正确指令！');window.location.href='./login.php';</script>";
      }
      $className="teachers";
       break;
      case 3:
      if ($shenfen!="student") {
        echo "<script>alert('身份码错误，请输入正确指令！');window.location.href='./login.php';</script>";
      }
      $className="students";
        break;
      default:
        
        break;
    }

    $brief=empty($_POST['brief'])?NULL:$_POST['brief'];
    $query="insert into ".$className." values(NULL,'".$_POST['name']."', '".$_POST['sex']."' ,'".$_POST['email']."', '".$_POST['password']."', '".$brief."')";
    
    $result=$mysql->query($query);
    if ($result) {
      echo "<script>alert('注册成功！');window.location.href='./signin.php';</script>";
    }else{
      echo "<script>alert('注册失败！');</script>";
    }
    $mysql->close();
  }

 ?>
<div class="container">

      <form class="form-horizontal" action="./login.php" method="post">
        <h2 class="form-signin-heading">注册</h2>

          <div class="form-group">
            <label class="col-sm-2 control-label">类别</label>
            <div class="col-sm-10">
              <select class="form-control" name="class">
              <!-- <option value="1">教务管理人员</option> -->
              <option value="2">教师</option>
              <option value="3">学生</option>
              </select>
            </div>
          </div> 
          <div class="form-group">   
            <label for="" class="col-sm-2 control-label">身份码</label>
            <div class="col-sm-10"><input type="text" id="" class="form-control" placeholder="身份码" name="yanzheng" required>
          </div> </div>

          <div class="form-group">
            <label for="name" class="col-sm-2 control-label">姓名</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" id="name" placeholder="请输入姓名" name="name" required>
            </div>
          </div>
        
         <div class="form-group">
            <label for="sex" class="col-sm-2 control-label">性别</label>
            <div class="col-sm-10">
              <label class="radio-inline">
                <input type="radio" name="sex" id="sex" value="m"> 男
              </label>
              <label class="radio-inline">
                <input type="radio" name="sex" id="sex" value="w"> 女
              </label>
            </div>
          </div>

         <!--  <div class="form-group">
            <label for="age" class="col-sm-2 control-label">年龄</label>
            <div class="col-sm-10">
              <input type="number" class="form-control" id="age" placeholder="请输入年龄" name="age">
            </div>
          </div> -->

         <div class="form-group">
            <label for="inputEmail" class="col-sm-2 control-label">邮箱</label>
            <div class="col-sm-10">
               <input type="email" id="inputEmail" class="form-control" placeholder="Email address" name="email" required>
            </div>
          </div> 
        
        <div class="form-group">
            <label for="inputPassword" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-10">
                <input type="password" id="inputPassword" class="form-control" placeholder="Password" name="password" required>
            </div>
          </div> 

          <div class="form-group">
            <label class="col-sm-2 control-label">简介</label>
            <div class="col-sm-10">
               <textarea class="form-control" rows="3" name="brief"></textarea>
            </div>
          </div> 
     
        <button class="btn btn-lg btn-primary btn-block" type="submit">注册</button>
      </form>
       <br>
      <a href="signin.php" class="btn btn-lg btn-success btn-block" role="button">登陆</a>
    </div> <!-- /container -->
<?php require_once 'footer.php'; ?>
